package com.itheima.myset;

import java.util.Comparator;
import java.util.TreeSet;

public class TeacherTreeSet {
    private String name;
    private int age;

    public TeacherTreeSet() {
    }

    public TeacherTreeSet(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "TeacherTreeSet{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}


class TeacherTest {
    public static void main(String[] args) {
        TreeSet<TeacherTreeSet> tst = new TreeSet<>(new Comparator<TeacherTreeSet>() {
            @Override
            public int compare(TeacherTreeSet o1, TeacherTreeSet o2) {
                int result = o1.getAge() - o2.getAge();
                return result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
            }
        });
        TeacherTreeSet t1 = new TeacherTreeSet("hznag", 15);
        TeacherTreeSet t2 = new TeacherTreeSet("xzca", 16);
        TeacherTreeSet t3 = new TeacherTreeSet("asdqwg", 15);
        tst.add(t1);
        tst.add(t2);
        tst.add(t3);
        System.out.println(tst);
    }
}